<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( !ispost( ) )
{
    exit();
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chk = new CheckMode_3d( $curruser['acl'], 3, $gametype );
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$g_betname_3or5 = judge_type( $gametype );
unset( $chk );
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
require_once( "class_3d/RateConfig_3d.php" );
require_once( "class_3d/SRate_3d.php" );
$ui = new UI_3D( true );
$conf = new Config();
$RateConfig_3d = new RateConfig_3d( $gametype );
$SRate_3d = new SRate_3d( $gametype );
$today = date( "Y-m-d" );
$bettypegroup = getvar( "palygroup" );
$betmin = $conf->get( "betmin_{$tbl}" );
$setMomney = getvar( "setMomney" );
$rcmp3 = $_POST['rcmp3'];
$rcmp2 = $_POST['rcmp2'];
$rcmp1 = $_POST['rcmp1'];
$disk = intval( getvar( "disk" ) );
if ( !isset( $curruser["disk{$disk}"] ) || $curruser["disk{$disk}"] != 1 )
{
    $ui->showErrorPage( "盘类错误" );
    exit();
}
$diskStr = $RateConfig_3d->diskArr[$disk];
$diskStr2 = $g_disk_name[$disk];
unset( $_POST['disk'] );
if ( is_array( $rcmp3 ) && is_array( $rcmp2 ) && is_array( $rcmp1 ) )
{
    $chkNum3 = count( $rcmp3 );
    $chkNum2 = count( $rcmp2 );
    $chkNum1 = count( $rcmp1 );
    $totalChkNum = $chkNum3 + $chkNum2 + $chkNum1;
    if ( $chkNum3 < 1 || $chkNum2 < 1 || $chkNum1 < 1 )
    {
        $ui->showErrorPage( "每位数至少勾选一个号码" );
        exit();
    }
    else
    {
        if ( 10 < $chkNum3 || 10 < $chkNum2 || 10 < $chkNum1 )
        {
            $ui->showErrorPage( "每位数最多勾选10个号码" );
            exit();
        }
        else
        {
            if ( $totalChkNum < 9 )
            {
                $ui->showErrorPage( "勾选的总号码量至少要9个" );
                exit();
            }
            else
            {
                if ( 21 < $totalChkNum )
                {
                    $ui->showErrorPage( "勾选的总号码量不可超过21个" );
                    exit();
                }
            }
        }
    }
}
else
{
    $ui->showErrorPage( "资料不齐全，无法下注" );
    exit();
}
if ( $curruser['enabled'] == 0 || $curruser['enabled'] == 2 )
{
    $ui->showErrorPage( "帐号已被暂停使用" );
    exit();
}
else if ( 1 < $curruser['acl'] )
{
    $ui->showErrorPage( "非会员无法下注" );
    exit();
}
if ( $bettypegroup != "rcmp" )
{
    $ui->showErrorPage( "不正确的玩法页面" );
    exit();
}
else if ( $setMomney < $betmin )
{
    $ui->showErrorPage( "下注金额不能小於最低限额({$betmin}元)" );
    exit();
}
include_once( "BetChk.php" );
$BetChk = new BetChk( $today, $gametype );
if ( $lotto_3d = $BetChk->chkBetDate( $today ) )
{
    $lotto_id = $lotto_3d['id'];
    $round = $lotto_3d['round'];
    $bettype = "35";
    $betSubIdx = "35_0";
    if ( !isset( $g_betname_3or5[$betSubIdx] ) )
    {
        $betOKFlag = false;
        $timeTemp = rand( 10, 99 )."2".rand( 0, 9 );
        $errMsg = "({$tbl})[betrcmpbeforedo]No.{$timeTemp} 会员下注:不被许\可的玩法:id-35, subid-0";
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $ui->showErrorPage( "下注失败。(errorNo.{$timeTemp})" );
        exit();
    }
    $chkNumFlag = $RateConfig_3d->chkRcmpNum( $rcmp3 );
    if ( $chkNumFlag !== false )
    {
        $betOKFlag = false;
        $timeTemp = rand( 10, 99 )."3".rand( 0, 9 );
        $errMsg = "({$tbl})[betrcmpbeforedo]No.{$timeTemp} 会员下注RCMP:不正确的内容:id-{$bettype},num3-".$chkNumFlag;
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $ui->showErrorPage( "下注失败。(errorNo.{$timeTemp})" );
        exit();
    }
    $chkNumFlag = $RateConfig_3d->chkRcmpNum( $rcmp2 );
    if ( $chkNumFlag !== false )
    {
        $betOKFlag = false;
        $timeTemp = rand( 10, 99 )."4".rand( 0, 9 );
        $errMsg = "({$tbl})[betrcmpbeforedo]No.{$timeTemp} 会员下注RCMP:不正确的内容:id-{$bettype},num2-".$chkNumFlag;
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $ui->showErrorPage( "下注失败。(errorNo.{$timeTemp})" );
        exit();
    }
    $chkNumFlag = $RateConfig_3d->chkRcmpNum( $rcmp1 );
    if ( $chkNumFlag !== false )
    {
        $betOKFlag = false;
        $timeTemp = rand( 10, 99 )."5".rand( 0, 9 );
        $errMsg = "({$tbl})[betrcmpbeforedo]No.{$timeTemp} 会员下注RCMP:不正确的内容:id-{$bettype},num1-".$chkNumFlag;
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $ui->showErrorPage( "下注失败。(errorNo.{$timeTemp})" );
        exit();
    }
    $tempRateBaseArr = $SRate_3d->getRates( $lotto_id, $disk, $bettype );
    if ( $tempRateBaseArr == false )
    {
        $betOKFlag = false;
        $timeTemp = rand( 10, 99 )."6".rand( 0, 9 );
        $errMsg = "({$tbl})[betrcmpbeforedo]No.{$timeTemp} 会员下注RCMP:无赔率资料:id-".$bettype;
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $ui->showErrorPage( "查无复式组合的赔率资料，无法下注。若有任何问题请洽管理员。" );
        exit();
    }
    $user_id = $SRate_3d->getAcl5ID( $curruser['id'], $curruser['acl'] );
    if ( $tempRateBaseArr2 = $SRate_3d->getRatesS( $lotto_id, $bettype, $user_id ) )
    {
        $tempRateArr = array();
        foreach ( $tempRateBaseArr as $key2 => $val2 )
        {
            $tempRateArr[$key2] = $tempRateBaseArr[$key2] - $tempRateBaseArr2[$key2];
        }
        $rateArr = $tempRateArr;
    }
    else
    {
        $rateArr = $tempRateBaseArr;
    }
    $checkArr = array();
    foreach ( $rcmp3 as $val3 )
    {
        foreach ( $rcmp2 as $val2 )
        {
            foreach ( $rcmp1 as $val1 )
            {
                $checkArr[] = $val3.$val2.$val1."";
            }
        }
    }
    $getRatesNumArr = $SRate_3d->getRatesNumArr( $lotto_id, $disk, $bettype, 0 );
    $getRatesSNumArr = $SRate_3d->getRatesSNumArr( $lotto_id, $user_id, $bettype, 0 );
    $totalRate = 0;
    $totalNum = 0;
    foreach ( $checkArr as $val )
    {
        $rate = $RateConfig_3d->getRateFromRateArr( $bettype, $val, $rateArr, $getRatesNumArr, $getRatesSNumArr );
        if ( $rate <= 1 )
        {
            $betOKFlag = false;
            $errMsg = "({$tbl})[betrcmpbeforedo]会员下注RCMP:赔率值错误:id-{$bettype},num-{$val},rate-".$rate;
            write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
            $ui->showErrorPage( "复式组合所勾选号码的组合中出现了错误的赔率值，无法下注。若有任何问题请洽管理员。" );
            exit();
        }
        $totalRate += $rate;
        ++$totalNum;
    }
    $rate = $totalRate / $totalNum / ( $chkNum3 * $chkNum2 * $chkNum1 );
    $rcmp3Str = implode( ",", $rcmp3 );
    $rcmp2Str = implode( ",", $rcmp2 );
    $rcmp1Str = implode( ",", $rcmp1 );
    if ( $rate <= 1 )
    {
        $betOKFlag = false;
        $errMsg = "({$tbl})[betrcmpbeforedo]会员下注RCMP:赔率值错误:id-".$bettype.",num-佰(".$rcmp3Str.");拾(".$rcmp2Str.");个(".$rcmp3Str."),rate-".$rate;
        write_exceptional_log( $curruser['id'], $curruser['acl'], $lotto_id, $errMsg );
        $note = "勾选的号码经计算後的赔率值小於1无法下注。";
    }
    else
    {
        $rate = round( $rate, 2 );
        $rate .= "<input type=\"hidden\" name=\"oldrate\" value=\"".$rate."\" />";
        $betOKFlag = true;
        $note = "";
        $rcmp3Str .= "<input type=\"hidden\" name=\"rcmp3str\" value=\"".$rcmp3Str."\" />";
        $rcmp2Str .= "<input type=\"hidden\" name=\"rcmp2str\" value=\"".$rcmp2Str."\" />";
        $rcmp1Str .= "<input type=\"hidden\" name=\"rcmp1str\" value=\"".$rcmp1Str."\" />";
        $setMomney .= "<input type=\"hidden\" name=\"setMomney\" value=\"".$setMomney."\" />";
    }
    $ui->header();
    echo "<form action=\"op.php?op=member_3d&fp=betrcmp_do&palygroup=".$bettypegroup."&gametype=".$gametype."&disk=".$disk."\" method=\"post\" onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
    echo "<input type=\"hidden\" value=\"".$bettypegroup."\" name=\"bettypegroup\" />";
    echo "<input type=\"hidden\" value=\"".$gametype."\" name=\"gametype\" />";
    echo "<input type=\"hidden\" value=\"".$disk."\" name=\"disk\" />";
    echo "<table class=\"tblMy3D\">";
    echo "<thead><tr class=\"title0 bgImg_".$gametype."\"><th colspan=2>".$tblName." 第 ".$round." 期  复式组合 您下注的是</th></tr>";
    echo "<tr class=\"bgClc_".$gametype."\"><th>位别</th><th>勾选号码</th></tr></thead>";
    echo "<tbody>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">佰位数</td><td>".$rcmp3Str."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">拾位数</td><td>".$rcmp2Str."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">个位数</td><td>".$rcmp1Str."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">盘类</td><td>".$diskStr2."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">赔率</td><td class=\"rate_th2\">".$rate."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">下注金额</td><td align=\"right\">".$setMomney."</td></tr>";
    echo "<tr class=\"td2\"><td class=\"bgClc_".$gametype."\" align=\"right\">说明</td><td>".$note."</td></tr>";
    $timebtnType = getvar( "timebtnType" ) == "checkbox" ? "checkbox" : "text";
    $backurl = "op.php?op=member_3d&fp=bet&palygroup={$bettypegroup}&timebtnType={$timebtnType}&gametype={$gametype}&disk={$disk}";
    if ( $betOKFlag )
    {
        $btnStr = "<input type=\"submit\" name=\"submit\" value=\"确定下注\" />&nbsp;&nbsp;<input name=\"reset\" type=\"reset\" value=\"取消下注\" onclick=\"javascript:window.top.mainFrame.location.href='".$backurl."';\" />";
        $focusStr = "document.forms[0].submit.focus();";
    }
    else
    {
        echo "<tr class=\"red\"><td colspan=\"2\" align=\"center\">无任何可下注资料</td></tr>";
        $btnStr = "<input name=\"reset\" type=\"reset\" value=\"回上一页\" onclick=\"javascript:window.top.mainFrame.location.href='".$backurl."';\" />";
        $focusStr = "";
    }
    echo "</tbody>";
    echo "</table>";
    echo $btnStr;
    echo "<input type=\"hidden\" value=\"".$timebtnType."\" name=\"timebtnType\" id=\"timebtnType\" />";
    echo "</form>";
    echo "<script>";
    echo $focusStr;
    echo "</script>";
    $ui->footer();
}
?>